from peewee import MySQLDatabase, Model, CharField, BooleanField, IntegerField


db = MySQLDatabase('Kyml',host ='47.107.159.28',user='root',passwd='kuaiyum')


class UserAc(Model):

    #用户名
    iuser = CharField()
    #发送流量
    isent=IntegerField()
    #接收流量
    irecv=IntegerField()
    #初始流量
    maxll=IntegerField(default='5242880')
    #密码
    pwd=CharField(column_name="pass")
    #激活
    i= BooleanField(default= True)
    #开始时间
    starttime=IntegerField(default=1551334648)
    #结束时间
    endtime = IntegerField(default=1651437739)
    #邮箱
    mail=CharField(default="")

    tian=IntegerField(default="99")
    dlid=IntegerField(default=0)
    tj_u=IntegerField(default=0)
    online=IntegerField(default=0)
    last_ip=CharField(default="")
    area=CharField(default="")
    isp=CharField(default="")
    client=CharField(default="")
    remote_port=IntegerField(default=0)
    xieyi=CharField(default="")
    login_time = IntegerField(default=0)
    line_id = IntegerField(default=0)


    class Meta:
        database = db
        table_name = 'openvpn'


def mysql(fun):
    """
    mysql打开和关闭操作
    :param fun:
    :return:
    """
    db.connect()
    def force(*args, **kwargs):
        return fun(*args, **kwargs)

    db.close()
    return force


#
# query = (UserAc
#          .select(UserAc.maxll)
#          .where(UserAc.iuser=='1123'))
#
# print(query.count())

# user=UserAc(iuser='wyndem1',pwd='123')
# user.save()


if __name__ == '__main__':
    ua = UserAc.get(UserAc.iuser == 'a')
    print(ua)